home *** CD-ROM | disk | FTP | other *** search
- Path: ohstpy.mps.ohio-state.edu!vancleef
- From: vancleef@ohstpy.mps.ohio-state.edu
- Newsgroups: comp.lang.c
- Subject: Re: 6 byte real to double; How?
- Message-ID: <1996Feb23.160719.8965@ohstpy>
- Date: 23 Feb 96 16:07:19 -0500
- References: <3128306A.21F@hsc.unt.edu> <4gg88a$3oi@aphex.direct.ca> <312DFBF2.74BB@hsc.unt.edu>
- Organization: The Ohio State University, Department of Physics
-
- In article <312DFBF2.74BB@hsc.unt.edu>, Steve Fogoros <sfogoros@hsc.unt.edu> writes:
- > Ed Toivanen wrote:
- >>
- >> In article <3128306A.21F@hsc.unt.edu>, sfogoros@hsc.unt.edu says...
- >> >
- >> >I have a lot of data files that were created by a pascal program. The
- >> >data is stored as 'file of real' meaning that each floating point value
- >> >is stored in six bytes. I need to access this data from a c program
- >> >(borland). I would like any assistance you could provide. I guess what
- >> >I need is a canned function that would take a 6 byte string (actually the
- >> >real), and return a double.
- >>
- >> You need to know exactly how reals are interpreted by your pascal program. The
- >> exact handling of a float is different(X bytes on the left side of the decimal,
- >> Y bytes for precision) even across different C compilers, so I don't think
- >> pascal would be much different in that respect. Once you know that, the rest is
- >> a few C line away.
- >>
- >> EdThank you for taking some time to consider my question. I should explain
- > though that I am not referring to the ascii representation of floating
- > point values, but the binary storage format. A six byte real (48 bits) is
- > divided into three fields: one sign bit (s), 39 bits for the significand
- > (f), and 8 bits for the exponent (e). According to Borland specification
- > the value is calculated as:
- > if 0 < e <= 255 then value = (-1)**s * 2**(e-129) * (1.f),
- > if e == 0 then value = 0.
-
-
- No. The bias is 127 NOT 129.
-
- > A double has one sign bit, 52 bits for the significand (which includes a
- > sign bit), and 11 bits for the exponent.
- >
- > The part I'm not sure about is biasing the exponents. The real is biased
- > by 129 and the double is biased by 1023. (I think/hope I've got that
- > right). So, if the real exponent is not zero, I add 894 to it and store
- > the result in the double exponent (11 bits). I would go with this except
- > some numbers convert correctly and some don't. (My testing protocol could
- > be in error as well.)
- >
- > I thought you would be interested in a more detailed description of the
- > problem. Also, others may have misunderstood my original question and I
- > hope this clarifies things.
- > --
- > Steve Fogoros, Academic Information Coordinator
- > University of North Texas Health Science Center
- > 3500 Camp Bowie Boulevard, Fort Worth, Texas 76107-2699
- > (817)-735-2162 sfogoros@hsc.unt.edu
- >
-